<template>
  <div class="container">
    <div v-if="show" class="wrap">
      <div class="w-title">
        我要充值
      </div>
      <div class="content">
        <div class="item">
          <div>可用余额：</div>
          <div>&nbsp;{{account.price}}&nbsp;元</div>
        </div>
        <div class="item" style="margin-bottom: 10px;">
          <div>金额（元）：</div>
          <a-input-number id="inputNumber" style="width:100px;margin-right: 5px;" 
            :formatter="value => `${value}`"
            :parser="value => value.replace(/[^\d]/g,'')"
            v-model="money" />
          <!-- <div style="font-size: 14px;">余额：{{account.price}}元</div> -->
          <!-- <a-input prefix="￥" style="width:200px;" v-model="money" type="number" /> -->
        </div>
        <div class="item desc">最小充值金额：1元，必须是整数单位</div>
        <a-button type="primary" @click="pay">充值</a-button>
      </div>
    </div>
    <div v-else></div >
  </div>
</template>

<script>
import { GET_REAL_NAME, ALIPAY } from '../server'
export default {
  layout: "main",
  components: {
  },
  data() {
    return {  
      show: false,
      money: null,
      account: {}
    };
  },
  created() {
    this.getRearName()
  },
  mounted() {
  },
  methods: {
    getRearName() {
      GET_REAL_NAME({
        type: 1
      }).then(res => {
        if (res.data == '审核中' || res.data == '审核失败' || res.data == '未认证') {
          this.$router.push('/mine/autonym')
        } else {
          GET_REAL_NAME({
            type: 2
          }).then(res => {
            this.account = res.data
            this.show = true
          })
        }
      });
    },
    pay() {
      if (this.money == null || this.money <= 0) {
        this.$message.error('请输入正确的金额！')
      } else {
        let mid = this.$store.state.member_id
        window.location.href = `http://php.itemplay.com/pay/Alipay/alipay?pay_type=1&member_id=${mid}&price=${this.money}`
      }
      // let mid = this.$store.state.member_id
      // window.location.href = `http://php.itemplay.com/pay/Alipay/alipay?pay_type=1&member_id=${mid}&price=0.01`

      // window.open(
      //   `http://php.itemplay.com/pay/Alipay/alipay?pay_type=1&member_id=${mid}&price=0.01`
      // );
      // if (this.money == null || this.money <= 0) {
      //   this.$message.error('请输入正确的金额！')
      // } else {
        // ALIPAY({
        //   pay_type: 1,
        //   price: this.money,
        // }).then(res => {
        //   // window.location.href=res;
        //       let mid = this.$store.state.member_id
        //       window.open(
        //         `http://php.itemplay.com/pay/Alipay/alipay?pay_type=1&member_id=${mid}&price=${this.money}`
        //       );

        // })
      // }
    }
  }
};
</script>
<style lang="less" scoped>
.container {
  // border: 3px solid #0084ff;
  // border-radius: 6px;
  padding: 0 236px;
}
.wrap {
  border: 3px solid #0084ff;
  border-radius: 6px;
  padding: 10px;
  min-height: 562px;
  .w-title {
    height: 40px;
    line-height: 40px;
    background: #0084ff;
    color: #fff;
    margin-bottom: 20px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: bold;
    padding-left: 16px;
  }
  .content{
    width: 300px;
    margin: 0 auto;
    .item {
      font-size: 14px;
      // font-weight: bold;
      color: rgba(0, 0, 0, 0.85);
      margin-bottom: 20px;
      display: flex;
      align-items: center;
    }
    .desc {
      color: #999;
      font-size: 14px;
      line-height: normal;
    }
  }
}
</style>